package com.mo.design.pattern.creational.factory;

public abstract class VehicleFactory02 {

    protected abstract Vehicle02 createVehicle(String item);

    public Vehicle02 orderVehicle(String size, String color) {
        Vehicle02 vehicle02 = createVehicle(size);
        vehicle02.testVehicle();
        vehicle02.setColor(color);
        return vehicle02;
    }

    public static void main(String[] args) {
        VehicleFactory02 carFactory = new CarFactory();
        Vehicle02 vehicle02 = carFactory.orderVehicle("large", "blue");
        System.out.println(vehicle02.color);
        System.out.println("-----------------------");
        VehicleFactory02 truckFactory = new TruckFactory();
        Vehicle02 vehicle021 = truckFactory.orderVehicle("small", "black");
        System.out.println(vehicle021.color);
        System.out.println("-----------------------");
        //  匿名内部类实现方法工厂
        VehicleFactory02 bikeFactory = new VehicleFactory02() {
            @Override
            protected Vehicle02 createVehicle(String item) {
                if (item.equals("small")) {
                    return new MountainBike();
                } else if (item.equals("large")) {
                    return new CityBike();
                }
                return null;
            }
        };
    }

}
